package com.fox.imagedb.listener;

import java.awt.Container;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

public class ImageDBMouseListener implements MouseListener {

	private Container container;

	public ImageDBMouseListener(Container container) {
		super();
		// this.container = getParentFrame(container);
		this.container = container;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		Container root = getParentFrame(container);
		if (root != null) {
			root.requestFocusInWindow();
		} else {
			System.out.println("oups");
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	private Container getParentFrame(Container component) {
		Container c = component;
		while (c.getParent() != null) {
			c = c.getParent();
		}

		if (c instanceof JFrame) {
			return c;
		}
		return null;
	}

}
